View Javadoc

1   // Interface.java, created Sat Mar 29  2:34:35 2003 by joewhaley
2   // Copyright (C) 2001-3 John Whaley <jwhaley@alum.mit.edu>
3   // Licensed under the terms of the GNU LGPL; see COPYING for details.
4   package joeq.ClassLib.ibm13_win32;
5   
6   import java.util.Collections;
7   import java.util.Iterator;
8   import joeq.Class.PrimordialClassLoader;
9   import joeq.Class.jq_Class;
10  import joeq.ClassLib.ClassLibInterface;
11  import joeq.Main.jq;
12  import joeq.Runtime.ObjectTraverser;
13  import jwutil.collections.AppendIterator;
14  
15  /***
16   * Interface
17   *
18   * @author  John Whaley <jwhaley@alum.mit.edu>
19   * @version $Id: Interface.java 1941 2004-09-30 03:37:06Z joewhaley $
20   */
21  public final class Interface extends joeq.ClassLib.Common.InterfaceImpl {
22  
23      /*** Creates new Interface */
24      public Interface() {}
25  
26      public Iterator getImplementationClassDescs(joeq.UTF.Utf8 desc) {
27          if (ClassLibInterface.USE_JOEQ_CLASSLIB && (desc.toString().startsWith("Ljava/") ||
28                                                      desc.toString().startsWith("Lcom/ibm/jvm/"))) {
29              joeq.UTF.Utf8 u = joeq.UTF.Utf8.get("Ljoeq/ClassLib/ibm13_win32/"+desc.toString().substring(1));
30              return new AppendIterator(super.getImplementationClassDescs(desc),
31                                        Collections.singleton(u).iterator());
32          }
33          return super.getImplementationClassDescs(desc);
34      }
35      
36      public ObjectTraverser getObjectTraverser() {
37          return ibm13_win32ObjectTraverser.INSTANCE;
38      }
39      
40      public static class ibm13_win32ObjectTraverser extends CommonObjectTraverser {
41          public static ibm13_win32ObjectTraverser INSTANCE = new ibm13_win32ObjectTraverser();
42          protected ibm13_win32ObjectTraverser() {}
43          public void initialize() {
44              super.initialize();
45              
46              // access the ISO-8859-1 character encoding, as it is used during bootstrapping
47              try {
48                  new String(new byte[0], 0, 0, "ISO-8859-1");
49              } catch (java.io.UnsupportedEncodingException x) {}
50              PrimordialClassLoader.loader.getOrCreateBSType("Lsun/io/CharToByteISO8859_1;");
51      
52              jq_Class k = (jq_Class)PrimordialClassLoader.loader.getOrCreateBSType("Ljava/net/URLClassLoader$ClassFinder;");
53              nullInstanceFields.add(k.getOrCreateInstanceField("name", "Ljava/lang/String;"));
54              
55              k = (jq_Class)PrimordialClassLoader.loader.getOrCreateBSType("Lsun/misc/Launcher;");
56              nullStaticFields.add(k.getOrCreateStaticField("launcher", "Lsun/misc/Launcher;"));
57              //k = (jq_Class)PrimordialClassLoader.loader.getOrCreateBSType("Ljava/net/URLClassLoader;");
58              //nullStaticFields.add(k.getOrCreateStaticField("extLoader", "Ljava/net/URLClassLoader;"));
59              k = PrimordialClassLoader.getJavaLangString();
60              nullStaticFields.add(k.getOrCreateStaticField("btcConverter", "Ljava/lang/ThreadLocal;"));
61              nullStaticFields.add(k.getOrCreateStaticField("ctbConverter", "Ljava/lang/ThreadLocal;"));
62              k = (jq_Class)PrimordialClassLoader.loader.getOrCreateBSType("Ljava/util/zip/ZipFile;");
63              nullStaticFields.add(k.getOrCreateStaticField("inflaters", "Ljava/util/Vector;"));
64              
65              // we need to reinitialize the inflaters array on startup.
66              if (jq.on_vm_startup != null) {
67                  Object[] args = { } ;
68                  joeq.Class.jq_Method init_inflaters = k.getOrCreateStaticMethod("init_inflaters", "()V");
69                  joeq.Bootstrap.MethodInvocation mi = new joeq.Bootstrap.MethodInvocation(init_inflaters, args);
70                  jq.on_vm_startup.add(mi);
71                  System.out.println("Added call to reinitialize java.util.zip.ZipFile.inflaters field on joeq startup: "+mi);
72              }
73          }
74          
75          public java.lang.Object mapInstanceField(java.lang.Object o, joeq.Class.jq_InstanceField f) {
76              if (IGNORE_THREAD_LOCALS) {
77                  jq_Class c = f.getDeclaringClass();
78                  if (c == PrimordialClassLoader.getJavaLangThread()) {
79                      String fieldName = f.getName().toString();
80                      if (fieldName.equals("threadLocals"))
81                          return java.util.Collections.EMPTY_MAP;
82                      if (fieldName.equals("inheritableThreadLocals"))
83                          return java.util.Collections.EMPTY_MAP;
84                  }
85              }
86              return super.mapInstanceField(o, f);
87          }
88      }
89  }